package pl.szpadel.android.gadu;

/// Simple object describing connection status
public class ConnectionState {
	
	// connection states
	public static final int CONNECTED = 0; // connected
	public static final int CONNECTING = 1; // disconnected, but trying to connect, no action needed
	public static final int DISCONNECTED = 2; // disconnected, and not attemtpint to connect
	
	// disconnect reasons
	public static final int REASON_NONE = 100; // disconnected on user demand
	public static final int REASON_LOGIN_FAILED = 101; // login failed
	public static final int REASON_NETWORK_PROBLEM = 103;
	public static final int REASON_DISCONNECTED_BY_USER = 104;
	
	private int mState;
	private int mReason;
	
	public int getState() {
		return mState;
	}
	
	public int getReason() {
		return mReason;
	}
	
	/// protected c-tor, use named constructors to create
	protected ConnectionState(int state, int reason) {
		mState = state;
		mReason = reason;
	}
	
	public static ConnectionState Connected() {
		return new ConnectionState(CONNECTED, REASON_NONE);
	}

	public static ConnectionState Connecting() {
		return new ConnectionState(CONNECTING, REASON_NONE);
	}
	
	public static ConnectionState Disconnected(int reason) {
		return new ConnectionState(DISCONNECTED, reason);
	}
	
	public String toString() {
		return "ConnectionState [state=" + mState + ", reason=" + mReason  + " ]";
	}
}
